﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ImageWater
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.CheckFileExists = true;
            dialog.CheckPathExists = true;
            dialog.Multiselect = true;
            dialog.Filter = "图片文件|*.jpg;*.gif;*.png;*.bmp";
            dialog.FileOk += new CancelEventHandler(open_FileOk);
            dialog.ShowDialog();


        }

        void open_FileOk(object sender, CancelEventArgs e)
        {
            OpenFileDialog dialog = sender as OpenFileDialog;
            foreach (var item in dialog.FileNames)
            {
                txtFilePaths.AppendText(item + Environment.NewLine);
            }

        }

        private void btnWater_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            folderDialog.ShowNewFolderButton = true;

            folderDialog.ShowDialog();

            if (this.txtFilePaths.Text.Length > 0)
            {
                string[] filePaths = this.txtFilePaths.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                Dictionary<string, string> dict = new Dictionary<string, string>();
                foreach (string filePath in filePaths)
                {
                    if (!dict.ContainsKey(filePath))
                    {
                        dict.Add(filePath, Path.Combine(folderDialog.SelectedPath, Path.GetFileName(filePath)));
                    }
                }
                foreach (var kv in dict)
                {
                    ImageWaterHandler.AddWaterText(kv.Key, "超级肥兔", kv.Value, 0.3, 20);
                }
            }
            else
            {
                MessageBox.Show("请选择文件");
            }

        }

        void saveDialog_FileOk(object sender, CancelEventArgs e)
        {
            SaveFileDialog saveDialog = sender as SaveFileDialog;


        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.txtFilePaths.Text = "";
        }
    }
}
